package com.taotao.service.impl;

import com.taotao.entity.Item;
import com.taotao.entity.ItemDesc;
import com.taotao.mapper.ItemDescMapper;
import com.taotao.mapper.ItemMapper;
import com.taotao.service.RestItemService;
import com.taotao.vo.ResultVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * author: 王明跃
 * Create at: 18/7/6下午2:46
 */
@Service
public class RestItemServiceImpl implements RestItemService {
    @Resource
    private ItemMapper itemMapper;
    @Resource
    private ItemDescMapper itemDescMapper;

    @Override
    public ResultVO delete(Long[] ids) {
        ResultVO resultVO = new ResultVO();
        int row = itemMapper.deleteByPrimaryKey(ids);
        if (row > 0) {
            resultVO.setStatus(200);
        }
        return resultVO;
    }

    @Override
    public int updateDown(Long[] ids) {
        return itemMapper.updateDown(ids);
    }

    @Override
    public int updateUp(Long[] ids) {
        return itemMapper.updateUp(ids);
    }

    @Override
    public ResultVO updateItem(Item item, String itemDesc) {
        ResultVO resultVO = new ResultVO();
        Long itemId = item.getId();
        ItemDesc itemDesc1 = new ItemDesc();
        itemDesc1.setItemDesc(itemDesc);
        itemDesc1.setItemId(itemId);
        int count = itemMapper.updateByPrimaryKeySelective(item);
        int count1 = itemDescMapper.updateItemDesc(itemDesc1);
        if (count > 0 && count1 > 0) {
            resultVO.setStatus(200);
            return resultVO;
        } else {
            resultVO.setStatus(20000000);
            return resultVO;
        }
    }
}
